<template>
  <div>
    <TopNavbar />
    <!-- <div class="featured-image-container">
      <img class="img-featured" src="../assets/19.jpg" alt="Featured Image" />
    </div> -->
    <div class="container" v-loading="isLoading" v-if="list.length">
      <div class="row">
        <div class="col-md-4" v-for="item in list" :key="item.id">
          <div class="card my-3">
            <img :src="item.cover" class="card-cover" alt="News Cover" />
            <div class="card-body">
              <h5 class="card-title">{{ item.title }}</h5>
              <p class="card-category">
                {{ typeText[item.type] }}
              </p>
              <p class="card-text">
                创建时间: {{ item.createTime | timeFormat }}
              </p>
              <p class="card-text">
                更新时间: {{ item.updateTime | timeFormat }}
              </p>
              <a
                href="#"
                class="btn btn-primary"
                @click.prevent="handleClick(item)"
                >查看详情</a
              >
            </div>
          </div>
        </div>
      </div>
    </div>

    <div v-else style="margin-top: 200px">
      <el-empty description="暂无内容" />
    </div>
  </div>
</template>
<script>
import TopNavbar from "@/components/TopNavbar.vue";
import request from "@/utils/request";

export default {
  name: "ChooseNewsList",
  components: {
    TopNavbar,
  },
  data() {
    return {
      list: [],
      isLoading: false,
      typeText: {
        1: "广西民族大学",
        2: "闽江师范高等专科学校",
        3: "福州市艺术学校",
        4: "中山大学",
        5: "香港中文大学",
        6: "印尼丹戎布拉大学孔院",
        7: "印尼阿拉扎大学",
        8: "泰国马哈沙拉坎大学",
        9: "老挝国立大学",
        10: "土耳中资民企商会",
        11: "印尼中资民企商会",
        12: "厄瓜多尔中华桥乡中心",
        13: "广西'桂姐姐'心理教育",
        14: "'茉莉姐姐'亲子教育工作室",
        15: "到海峡的另一边去",
        16: "顶梁柱母亲心理服务",
        17: "中学心理筛查",
        18: "'青苗计划'社区家长课堂",
        19: "守护星星畅享才艺",
        20: "成长助学",
        21: "义工风采",
      },
    };
  },
  created() {
    this.type = this.$route.query.type;
    this.load();
  },
  methods: {
    handleClick(item) {
      this.$router.push({ name: "NewsDetail", params: { id: item.id } });
    },
    load() {
      this.isLoading = true;
      request
        .getRequest(`api/essay/list/choose/` + this.type)
        .then((res) => {
          this.isLoading = false;
          if (res && res.data) {
            this.list = res.data.data;
          }
        })
        .catch((error) => {
          this.$message({
            message: "加载失败",
            type: "error",
          });
        });
    },
  },
  watch: {
    $route(to, from) {
      this.type = to.query.type;
      this.load();
    },
  },
};
</script>

<style scoped>
.featured-image-container {
  width: 100%;
  overflow: hidden;
  max-height: 500px;
}

.img-featured {
  width: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.img-featured:hover {
  transform: scale(1.1);
}

.container {
  width: 1000px;
  margin: auto;
  padding: 40px 20px;
  margin-top: 10px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  margin-right: -15px;
  margin-left: -15px;
}

.col-md-4 {
  position: relative;
  width: 100%;
  padding-right: 15px;
  padding-left: 15px;
}

.container {
  padding: 20px;
}

.card {
  position: relative;
  border: none;
  border-radius: 8px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
  background-color: #f9f9f9; /* 调整卡片背景颜色 */
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
  transform: translateY(-5px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.card-cover {
  width: 100%;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
  /* object-fit: cover; */
}

.card-body {
  padding: 15px 20px;
}

.card-title {
  font-size: 40px;
  color: #333;
  font-weight: bold;
}

.card-category {
  font-size: 20px;
  font-weight: bold;
  color: #666;
}

.card-text {
  font-size: 15px;
  color: #666;
}

.btn-primary {
  background-color: #00bc70;
  border: none;
  border-radius: 4px;
  padding: 10px 20px;
  font-size: 16px;
  color: white;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  transition: background-color 0.3s ease;
  margin-top: 10px;
}
.btn-primary:hover {
  background-color: #0b9660;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.btn-primary:hover {
  background-color: #0b9660;
}
</style>
